package com.woniuxy.store.core.controller;


import com.woniuxy.common.CommonResult;
import com.woniuxy.store.core.mapper.MdStorefirstMapper;
import com.woniuxy.store.core.model.MdStorefirst;
import com.woniuxy.store.core.model.MdStoresecond;
import com.woniuxy.store.core.service.MdStorefirstService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@RestController
@RequestMapping("mdStorefirst")
public class MdStorefirstController {
    @Autowired
    MdStorefirstService mdStorefirstService;

    //查新所有一级菜单
    @GetMapping("/selectAll")
    public CommonResult selectAll(){
        List<MdStorefirst> storefirstList=this.mdStorefirstService.list();
        return CommonResult.success(storefirstList);
    }

    //查询一个一级菜单名字
    @GetMapping("/selectOne/{firstId}")
    public CommonResult selectOne(@PathVariable("firstId") int firstId) {
        MdStorefirst  mdStorefirst=this.mdStorefirstService.getById(firstId);
        return CommonResult.success(mdStorefirst);
    }

    //修改一级菜单信息
    @PostMapping("updateOne")
    public CommonResult updateOne(@RequestBody MdStorefirst mdStorefirst){
        boolean b=  this.mdStorefirstService.updateById(mdStorefirst);
        if(b){
            return CommonResult.success("更新成功");}
        else {
            return CommonResult.fail();
        }
    }

    //增加一个一级菜单信息
    @PostMapping("/insertOne")
    public CommonResult insertOne(@RequestBody MdStorefirst mdStorefirst){
        this.mdStorefirstService.insertOne(mdStorefirst);
        return CommonResult.success("插入成功");
    }
    //删除一个一级菜单信息
    @GetMapping("delectOne/{firstId}")
    public CommonResult delectOnestore(@PathVariable("firstId") int firstId) {
        this.mdStorefirstService.delectOne(firstId);
        return CommonResult.success("注销成功");
    }

    @GetMapping("secondServe/{firstId}")
    public List<MdStoresecond> secondServe(@PathVariable Integer firstId){
        List<MdStoresecond> abc = this.mdStorefirstService.abc(firstId);
        return abc;
    }

    @GetMapping("delect/{firstId}")
    public CommonResult delect(@PathVariable("firstId") int firstId) {
        this.mdStorefirstService.delect(firstId);
        return CommonResult.success("注销成功");
    }

    @GetMapping("/selectAllServe")
    public CommonResult selectAllServe(){
        List<MdStorefirst> storefirstList=this.mdStorefirstService.selectAll();
        return CommonResult.success(storefirstList);
    }


}

